{% extends "base.html" %}
{% block content %}
<div class="splash">
    <!-- 背景音乐（静音自动播放） -->
    <audio id="bg-audio" autoplay loop muted>
        <source src="{{ url_for('static', filename='audio/background_music.mp3') }}" type="audio/mpeg">
   </audio>

    <!-- 音量控制按钮 -->
    <button id="volume-toggle" class="volume-btn">
        <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.879 12l1.586-1.586a6.378 6.378 0 018.965 0L21.121 12 19.535 13.586a6.378 6.378 0 01-8.965 0L2.879 12z" />
        </svg>
    </button>

    <!-- 标题与副标题 -->
     
    <h1 class="splash-title"> <i class="fa fa-code text-primary text-10xl mr-2"></i> OnlineJudge</h1>
    <p class="splash-subtitle">在这里挑战算法难题，记录代码成长轨迹</p>
    
    <!-- 初始按钮：开始探索 -->
    <button class="splash-btn" id="exploreBtn">开始探索</button>
    
    <!-- 登录选项（初始隐藏） -->
    <div class="login-options" id="loginOptions">
        <a href="{{ url_for('login') }}" class="splash-btn login-btn">账号登录</a>
        <a href="{{ url_for('guest_login') }}" class="splash-btn guest-btn">游客登录</a>
    </div>
</div>

<style>
/* 背景与标题动画（保留） */
.splash {
    position: fixed; top: 0; left: 0; 
    width: 100vw; height: 100vh; 
    overflow: hidden;
    background: 
        linear-gradient(180deg, rgba(0, 0, 0, 1), rgba(255, 255, 255, 0)), 
        url("/static/images/background.jpg") center/cover no-repeat; 
    background-size: 400% 400%, cover; 
    animation: black-fade 15s infinite alternate; 
    display: flex; 
    flex-direction: column; 
    justify-content: center; 
    align-items: center; 
    text-align: center; 
    color: #fff; 
}
@keyframes black-fade {
    0% { background-position: 0% 100%; }
    100% { background-position: 0% 0%; }
}
.splash-title {
    font-size: 4.5rem; margin-bottom: 1rem;
    animation: scale-in 1s ease-out;
    text-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
@keyframes scale-in {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}
.splash-subtitle {
    font-size: 1.4rem; margin-bottom: 2.5rem;
    animation: fade-in 1.5s ease-in;
    text-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
@keyframes fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 按钮样式（核心修复：确保可点击） */
.splash-btn {
    padding: 1rem 2.5rem;
    border-radius: 30px;
    font-weight: 600;
    transition: all 0.3s ease;
    border: none;
    cursor: pointer;
    position: relative; /* 修复层级问题 */
    z-index: 1;         /* 确保按钮在最上层 */
}
#exploreBtn {
    background: #fff;
    color: #000; 
    animation: slide-up 2s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
#exploreBtn:hover {
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(255,255,255,0.8);
}
@keyframes slide-up {
    from { transform: translateY(50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* 登录选项容器（初始隐藏） */
.login-options {
    display: none; 
    flex-direction: row;
    gap: 1rem;
    margin-top: 2rem;
    animation: fadeIn 0.5s ease;
}
/* 响应式适配 */
@media (max-width: 600px) {
    .login-options {
        flex-direction: column;
    }
}
/* 账号登录按钮 */
.login-btn {
    background: #4285f4;
    color: #fff;
}
/* 游客登录按钮 */
.guest-btn {
    background: #f1f1f1;
    color: #333;
}
/* 按钮悬停效果 */
.login-btn:hover, .guest-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.1);
}

/* 音量按钮（保留） */
.volume-btn {
    position: fixed; 
    bottom: 2rem; 
    right: 2rem; 
    background: rgba(255,255,255,0.2);
    border: none; 
    border-radius: 50%; 
    width: 48px; 
    height: 48px; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    cursor: pointer; 
    transition: all 0.3s ease; 
    z-index: 9999; /* 强制最高层级 */
}
.volume-btn:hover {
    background: rgba(255,255,255,0.4);
    transform: scale(1.1);
}
.volume-btn svg {
    color: #fff; 
    width: 24px; 
    height: 24px;
}
.volume-btn.muted svg {
    opacity: 0.6;
}

/* 动画定义 */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
</style>

<script>
// 所有交互逻辑包裹在 DOM 加载完成后执行
document.addEventListener('DOMContentLoaded', () => {
    // ========== 探索按钮切换逻辑 ==========
    const exploreBtn = document.getElementById('exploreBtn');
    const loginOptions = document.getElementById('loginOptions');

    if (!exploreBtn || !loginOptions) {
        console.error('[错误] 未找到探索按钮或登录选项容器！');
        return;
    }

    exploreBtn.addEventListener('click', () => {
        console.log('[调试] 开始探索按钮被点击！'); // 调试日志
        exploreBtn.style.display = 'none';
        loginOptions.style.display = 'flex';
    });

    // ========== 音量控制逻辑 ==========
    const audio = document.getElementById('bg-audio');
    const volumeBtn = document.getElementById('volume-toggle');

    if (!audio || !volumeBtn) {
        console.error('[错误] 未找到音频或音量按钮！');
        return;
    }

    volumeBtn.addEventListener('click', () => {
        audio.muted = !audio.muted;
        volumeBtn.classList.toggle('muted');
        
        if (audio.muted) {
            volumeBtn.innerHTML = `
            <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
              <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.879 11.121a2 2 0 010 2.828l-7 7A2 2 0 014 19V5a2 2 0 011.879-1.995l7-7a2 2 0 012.828 0l7 7A2 2 0 0120 5v14a2 2 0 01-1.879 1.995l-7 7a2 2 0 01-2.828 0l-7-7z" />
            </svg>
            `;
        } else {
            volumeBtn.innerHTML = `
            <svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
              <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" />
              <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.879 12l1.586-1.586a6.378 6.378 0 018.965 0L21.121 12 19.535 13.586a6.378 6.378 0 01-8.965 0L2.879 12z" />
            </svg>
            `;
        }
    });
});
</script>
{% endblock %}